package com.baijiaoxi.utils.sms.aliyun.model;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import lombok.Data;

@Data
public class AliyunSmsConfig {
    public static String product = "Dysmsapi";
    public static String domain = "dysmsapi.aliyuncs.com";
    public static String defaultConnectTimeout = "10000";
    public static String defaultReadTimeout = "10000";
    public static String endpointName = "cn-hangzhou";
    public static String regionId = "cn-hangzhou";
    private String accessKeyId = "";
    private String accessKeySecret = "";


    public IAcsClient buildClient() throws ClientException {

        //可自助调整超时时间
        System.setProperty("sun.net.client.defaultConnectTimeout", this.defaultConnectTimeout);
        System.setProperty("sun.net.client.defaultReadTimeout", this.defaultReadTimeout);
        //初始化acsClient,暂不支持region化
        IClientProfile profile = DefaultProfile.getProfile(regionId, this.accessKeyId, this.accessKeySecret);
        DefaultProfile.addEndpoint(endpointName, regionId, this.product, this.domain);
        IAcsClient acsClient = new DefaultAcsClient(profile);
        return acsClient;
    }

    public static IAcsClient buildClient(String accessKeyId, String accessKeySecret) throws ClientException {
        //可自助调整超时时间
        System.setProperty("sun.net.client.defaultConnectTimeout", defaultConnectTimeout);
        System.setProperty("sun.net.client.defaultReadTimeout", defaultReadTimeout);
        //初始化acsClient,暂不支持region化
        IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
        DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
        IAcsClient acsClient = new DefaultAcsClient(profile);
        return acsClient;

    }
}
